/**
 * Created by wk on 2017/4/18.
 */
(function() {
	var app = angular.module('EnterDirective', []);
	app.directive('ngEnter', function() {
		return {
			restrict : 'A',
			require : '?ngModel',
			link : function($scope, element, attrs, controller) {
				element.bind("keydown keypress", function(event) {
					if (event.which === 13) {
						$scope.$apply(function() {
							$scope.$eval(attrs.ngEnter);
						});
						event.preventDefault();
					}
				});
			}
		}
	});
})()